#include "ID_Manager.h"

class ID_Manager_Cleaner {
public:
    ~ID_Manager_Cleaner() {
        ID_Manager::destroy();
    }
} ID_Manager_cleaner_instance;

ID_Manager* ID_Manager::instance = NULL;

ID_Manager::ID_Manager()
{
    if(Debug::test(DEBUG_CREATE_DELETE)) {
        cout << "ID_Manager Created" << endl;
    }
    m_strNewId = "AAAAAAAA";
}

/*
ID_Manager* ID_Manager::get_instance() {
    if(!instance) {
        instance = new ID_Manager();
    }
    return instance;
}*/

void ID_Manager::destroy() {
    if( instance) {
        delete(instance);
        instance = NULL;
        if(Debug::test(DEBUG_CREATE_DELETE)) {
            cout << "ID_Manager Destroyed" << endl;
        }
    }
}

string &ID_Manager::get_ID()
{
    m_mutex.lock();
	for (int i = m_strNewId.length() - 1; i ; i--) {
		if (m_strNewId[i] < 'Z') {
			++m_strNewId[i];
			break;
		} else {
			m_strNewId[i] = 'A';
		}
	}
	string &tmp = m_strNewId;
    m_mutex.unlock();
	return tmp;
}
